#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

#define MAX_SIZE 5
typedef int EleType;

typedef struct circleQueue{
    EleType data[MAX_SIZE];
    int rear, front;
} circleQueue;

void initCircleQueue(circleQueue *q) {
    q->rear = 0;    // 直接设置结构体成员
    q->front = 0;   // 直接设置结构体成员
    for(int i=0; i<MAX_SIZE; i++) {
        q->data[i] = 0;
    }
}

bool isEmpty(circleQueue *q) {
    return q->rear == q->front;
}

bool isFill(circleQueue *q) {
    return q->front == (q->rear + 1 ) % MAX_SIZE;
}


void inQueue (circleQueue *q, int value) {
    if(isFill(q)) return;
    q->data [q->rear] = value;
    q->rear = (q->rear + 1) % MAX_SIZE;
}

void deQueue(circleQueue *q, int *value) {
    if (isEmpty(q)) return;
    *value = q->data[q->front];
    q->front = (q->front + 1) % MAX_SIZE;

}

void printCircleQueue(circleQueue *q) {
    if (isEmpty(q)) return;
    int idx = q->front;
    while (idx != q->rear) {
        printf("value is %d\n", q->data[idx]);
        idx = (idx + 1) % MAX_SIZE;
    }
    printf("\n");

}

int main() {
    circleQueue q;
    initCircleQueue(&q);
    inQueue(&q, 1);
    inQueue(&q, 2);
    inQueue(&q, 3);
    inQueue(&q, 4);
    inQueue(&q, 5);
    inQueue(&q, 6);
    printCircleQueue(&q);

}






